package com.qt.socket;

import java.io.IOException;
import java.net.*;

/**
 * @Author zsf
 * @Date 2023/10/5 1:27
 * @Version 1.0
 */
public class ReceiveMessageDemo {

    public static void main(String[] args) throws IOException {

        DatagramSocket ds = new DatagramSocket(8888);
        byte[] bytes = new byte[1024];
        DatagramPacket dp = new DatagramPacket(bytes, bytes.length);
        ds.receive(dp);

        byte[] data = dp.getData();
        System.out.println("接收到的数据：" + new String(data,0,dp.getLength()));
        System.out.println("发送方：" + dp.getAddress().getHostAddress());
        ds.close();
    }

}
